package com.wry.wry_test.algorithm;

import java.util.*;

/**
 * @Author: wangrongyi
 * @Date: 2024/11/22 15:23
 * @Description:
 */
public class Day13 {
    public static List<Integer> solution(List<Integer> a, List<Integer> b) {
        // write code here
        int i = a.size() - 1, j = b.size() - 1;
        List<Integer> result = new ArrayList<>();
        while (i >= 0 && j >= 0) {
            if (Objects.equals(a.get(i), b.get(j))) {
                result.add(a.get(i));
                i--;
                j--;
            } else {
                if (a.get(i) > b.get(j)) {
                    i--;
                } else {
                    j--;
                }
            }
        }
        return result;
    }

    public static void main(String[] args) {
        System.out.println(solution(Arrays.asList(1, 2, 3, 7), Arrays.asList(2, 5, 7)).equals(Arrays.asList(7, 2)));
        System.out.println(solution(Arrays.asList(1, 4, 8, 10), Arrays.asList(2, 4, 8, 10)).equals(Arrays.asList(10, 8, 4)));
        System.out.println(solution(Arrays.asList(3, 5, 9), Arrays.asList(1, 4, 6)).equals(Collections.emptyList()));
        System.out.println(solution(Arrays.asList(1, 2, 3), Arrays.asList(1, 2, 3)).equals(Arrays.asList(3, 2, 1)));
    }
}
